#include "..\List\LIST.h"

enum Client_Search {Search_By_ID,Search_By_Name,Search_By_Phone}; 

typedef enum Client_Search Client_Search_Type;

typedef struct {
	char ID[10];
	char Name[20];
	char Family[20];
	char City[20];
	char Street[20];
	char Phone[20];
	byte Active;
	byte Gender;
    
	unsigned char RequestCount;
	List RequestList;

}Client;

typedef struct
{
	DemandProperty *D;
	DemandProperty *P;
	Client *ClientPointer;
	
	int PropertyIndex;
	int must;
	int addition;
	int ValidMatchIndex;

}Match_Result;


typedef int (*CompareFuncType)(const void *arg1, const void *arg2);

typedef int (*BubbleFuncType)(const Demand d1,const Demand d2);

typedef void (*VoidCallBack)();


void FillDemandInfo(DemandProperty *D,char **BUF);
void WriteClientsToFile(Client *ClientsArray,int *ClientCount);
Client* LoadClientsFromFile(int *);
int ReadClientFromUser(Client **,int *);
void Add_New_Client(Client **,int *,VoidCallBack CB);
DemandProperty * ReadDemandFromUser();
void ShowAllClients(Client **ClientsArray,int *ClientCount,VoidCallBack CB);
int ShowClient(Client **ClientsArray,int *ClientCount,Client *C,int index);
int SelectClientFromList(Client *,int *);
void UpdateClients(Client **,int *,VoidCallBack CB);
void Start_Update_Client(Client *ClientsArray,int cid);
void DeleteClients(Client **,int *,VoidCallBack CB);
void Start_Delete_Client(Client **ClientsArray,int *ClientCount,int cid);
void SearchClients(Client **ClientsArray,int *ClientCount,VoidCallBack CB);
int Select_Client_Request(Client C);
void Start_Edit_Demands(Client *ClientsArray,int *ClientCount,int cid);
void Add_Demand_To_Client(Client *ClientsArray,int *ClientCount,int cid);
void Delete_Demand_From_Client(Client *ClientsArray,int *ClientCount,int cid);

void Client_Update_Name(Client *ClientsArray,int clientid);
void Client_Update_Family(Client *ClientsArray,int clientid);
void Client_Update_City(Client *ClientsArray,int clientid);
void Client_Update_Street(Client *ClientsArray,int clientid);
void Client_Update_Phone(Client *ClientsArray,int clientid);
void Client_Update_Active(Client *ClientsArray,int clientid);
void Client_Update_Gender(Client *ClientsArray,int clientid);
void Client_Update_Requests(Client *ClientsArray,int cid);

void Client_Update_Demands_Kind(Client *ClientsArray,int DemandIndex,int cid);
void Client_Update_Demands_Type(Client *ClientsArray,int DemandIndex,int cid);
void Client_Update_Demands_Price(Client *ClientsArray,int DemandIndex,int cid);
void Client_Update_Demands_City(Client *ClientsArray,int DemandIndex,int cid);
void Client_Update_Demands_Rooms(Client *ClientsArray,int DemandIndex,int cid);

int  Client_Insert_ID(Client *C,char *msg);
int Client_Insert_Between(byte *b,const char *arr[],int size,char *Header);
int Client_Insert_Integer(int *i,int maxdigits,char *Header);
int Client_Insert_String(char *c,char *Header,int maxsize,char *range);
int Client_Insert_Byte(byte *i,int maxdigits,char *Header);


int Client_Sort_ID(const void *arg1, const void *arg2);
int Client_Sort_Name(const void *arg1, const void *arg2);
int Client_Sort_Phone(const void *arg1, const void *arg2);

int FindClientID(Client *ClientsArray,int *ClientCount,Client *C);

void ClientsOptions();
void Show_Reports(Client *ClientsArray,int *ClientCount,List PropertiesList,int *PropertiesCount);
void Show_Reports_Sort_Demands(Client *ClientsArray,int *ClientCount);
void Show_Reports_Sort_Clients(Client *ClientsArray,int *ClientCount,int repid);
void Show_Reports_List_Demands_By_Client(Client *ClientsArray,int *ClientCount);
void Print_Demands_In_Recursion(Position L,int index);

void bubble_sort(Demand *Arr, int size,BubbleFuncType B);
int Sort_Demand_By_Price(const Demand d1,const Demand d2);
int Sort_Demand_By_City(const Demand d1,const Demand d2);
int Sort_Demand_By_Type(const Demand d1,const Demand d2);

void FreeClientAllocationsBeforeExit(Client *ClientsArray,int *ClientCount);
